package com.gaswell;

import com.gaswell.service.StorageService;
import com.gaswell.storage.StorageProperties;
import com.github.pagehelper.PageHelper;
import javafx.application.Application;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.Properties;


@SpringBootApplication
@EnableScheduling
@EnableConfigurationProperties(StorageProperties.class)
@EnableAsync
public class GaswellApplication {

	public static void main(String[] args) {
		SpringApplication.run(GaswellApplication.class, args);

	}



	@Bean
	CommandLineRunner init(StorageService storageService) {
		return (args) -> {
			storageService.init();
		};
	}

	//配置mybatis的分页插件pageHelper
	@Bean
	public PageHelper pageHelper() {
		PageHelper pageHelper = new PageHelper();
		Properties props = new Properties();
		props.setProperty("offsetAsPageNum","true");
		props.setProperty("rowBoundsWithCount","true");
		props.setProperty("reasonable","true");
		props.setProperty("dialect", "mysql"); //配置mysql数据库的方言
		props.setProperty("supportMethodsArguments", "true");// 表示支持从接口中读取pageNum和pageSize
		pageHelper.setProperties(props);
		return pageHelper;
	}

}
